/**
 * Created by chenlei on 14-12-20.
 */
package utils {
import flash.geom.Point;

import lzm.starling.STLConstant;

import starling.display.DisplayObject;

public class Kit {
    public function Kit() {
    }

    /**
     *
     * @param target
     * @return
     */
    public static function midPoint(target:DisplayObject):Point {
        return new Point((STLConstant.StageWidth - target.width) / 2, (STLConstant.StageHeight - target.height) / 2);
    }


    /**
     * 产生某个区间的随机数
     * @param min
     * @param max
     * @return
     */
    public static function Rnd(min:Number, max:Number):Number {
        return min + (Math.random() * (max - min + 1));
    }


    /**
     * 防止 越界  注意 注册点在原点
     * @param obj
     */
    public static function clame(obj:Object):void {
        if (obj.x < 0) {
            obj.x = 0;
        }

        if (obj.x + obj.width >= STLConstant.StageWidth) {
            obj.x = STLConstant.StageWidth - obj.width;
        }

        if (obj.y < 0) {
            obj.y = 0;
        }
        if (obj.y + obj.height > STLConstant.StageHeight) {
            obj.y = STLConstant.StageHeight - obj.height;
        }

    }
}
}
